import java.math.BigInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-11-04
 * Time: 20:38
 */
public class Test {
    //方法一：解决六位数相加不越界
    public static String bigNumSum(String s,String t){
        int sum=0;
        if (s == "") {
            s="0";
        }
        if(t == ""){
            t="0";
        }
        int num1=Integer.valueOf(s);
        int num2=Integer.valueOf(t);
        sum=num1+num2;

        return String.valueOf(sum);
    }
    public static String bigNumSum2(String s,String t){
        BigInteger num1 = new BigInteger(s);
        BigInteger num2 = new BigInteger(t);
        return num1.add(num2).toString();
    }

    public static String bigNumSum3(String s,String t){
        int i = s.length() - 1, j = t.length() - 1;
        int temp = 0;//表示进位的那个1
        StringBuilder out = new StringBuilder();
        while (i >= 0 || j >= 0 || temp != 0) {
            temp +=   i >= 0 ? s.charAt(i--) - '0' : 0;
            temp +=   j >= 0 ? t.charAt(j--) - '0' : 0;
            out.append(temp % 10);
            temp = temp / 10;
        }
        return out.reverse().toString();
    }
    public static void main(String[] args) {
        String sum=bigNumSum3("987","365");
        System.out.println(sum);
    }

}
